package com.xwj.exception.solution_3.demo.controller;

import com.xwj.common.util.R;
import com.xwj.exception.common.exceptions.BusinessException;
import com.xwj.exception.solution_3.demo.entity.Employe;
import com.xwj.exception.solution_3.demo.enums.BusinessResponseEnum;
import com.xwj.exception.solution_3.demo.service.EmployeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xiaowajiang
 * @Date: 2022-04-05 15:49
 * @Description:
 **/
@Slf4j
@RestController
@Api(value = "EmployeController", tags = "方案3 - 统一异常处理")
public class EmployeController {

    @Autowired
    private EmployeService employeService;

    @ApiOperation(value = "获取员工信息", position = 1)
    @PostMapping("solution_3/business/exception/getEmploye")
    public R getEmploye(@RequestParam Integer id) {
        Employe employe = employeService.selectById(id);
        if (employe == null) {
            BusinessResponseEnum responseEnum = BusinessResponseEnum.EMPLOYE_NOT_FOUND;
            throw new BusinessException(responseEnum.getCode(), responseEnum.getMessage());
        }
        return R.ok().put("data", employe);
    }

}
